import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";

type Result = {
  code: boolean;
  data?: Array<any>;
  msg: string;
};

type ResultTable = {
  success: boolean;
  data?: {
    /** 列表数据 */
    list: Array<any>;
    /** 总条目数 */
    total?: number;
    /** 每页显示条目个数 */
    pageSize?: number;
    /** 当前页数 */
    currentPage?: number;
  };
};

/** 获取系统管理-用户管理列表 */
export const getUserList = (data?: object) => {
  return http.request<ResultTable>(
    "post",
    baseUrlApi("/admin/system/admin/list"),
    {
      data
    }
  );
};

/** 获取系统管理-修改用户 */
export const updateUser = (data?: object) => {
  return http.request<Result>("put", baseUrlApi("/admin/system/admin/update"), {
    data
  });
};

/** 获取系统管理-新增用户 */
export const addUser = (data?: object) => {
  return http.request<Result>("post", baseUrlApi("/admin/system/admin/add"), {
    data
  });
};

/** 获取系统管理-删除用户 */
export const deleteUser = (params?: object) => {
  return http.request<Result>(
    "delete",
    baseUrlApi("/admin/system/admin/delete"),
    {
      params
    }
  );
};

/** 系统管理-批量删除用户 */
export const batchDeleteUser = (data?: Array<number>) => {
  return http.request<Result>(
    "delete",
    baseUrlApi("/admin/system/admin/batch_delete"),
    {
      data
    }
  );
};

/** 获取用户详情 */
export const getUserInfo = (params?: object) => {
  return http.request<Result>("get", baseUrlApi("/admin/system/admin/info"), {
    params
  });
};

/** 获取系统管理-修改用户状态 */
export const updateUserStatus = (params?: object) => {
  return http.request<Result>("put", baseUrlApi("/admin/system/admin/status"), {
    params
  });
};

/** 获取系统管理-用户管理-分配角色 */
export const assignRole = (data?: object) => {
  return http.request<Result>(
    "post",
    baseUrlApi("/admin/system/admin/assign"),
    { data }
  );
};

/** 用户管理-重置密码 */
export const resetPassword = (params?: object) => {
  return http.request<Result>(
    "post",
    baseUrlApi("/admin/system/admin/reset_password"),
    {
      params
    }
  );
};

/** 用户管理-修改头像 */
export const updateAvatar = (params?: object) => {
  return http.request<Result>(
    "post",
    baseUrlApi("/admin/system/admin/update_avatar"),
    {
      params
    }
  );
};

/** 系统管理-用户管理-获取所有角色列表 */
export const getAllRoleList = () => {
  return http.request<Result>("post", baseUrlApi("/admin/system/role/all"));
};

/** 系统管理-用户管理-根据userId，获取对应角色id列表（userId：用户id） */
export const getRoleIds = (params?: object) => {
  return http.request<Result>("get", baseUrlApi("/admin/system/admin/roles"), {
    params
  });
};

/** 获取系统管理-角色管理列表 */
export const getRoleList = (data?: object) => {
  return http.request<ResultTable>(
    "post",
    baseUrlApi("/admin/system/role/list"),
    { data }
  );
};

/** 获取系统管理-修改角色 */
export const updateRole = (data?: object) => {
  return http.request<Result>("put", baseUrlApi("/admin/system/role/update"), {
    data
  });
};

/** 获取系统管理-新增角色 */
export const addRole = (data?: object) => {
  return http.request<Result>("post", baseUrlApi("/admin/system/role/add"), {
    data
  });
};

/** 获取系统管理-删除角色 */
export const deleteRole = (params?: object) => {
  return http.request<Result>(
    "delete",
    baseUrlApi("/admin/system/role/delete"),
    {
      params
    }
  );
};

/** 导出角色 */
export const exportRole = (data?: object) => {
  return http.request<any>(
    "post",
    baseUrlApi("/admin/system/role/export"),
    { responseType: "blob" },
    {
      data
    }
  );
};

/** 获取系统管理-菜单管理列表 */
export const getMenuList = (params?: object) => {
  return http.request<Result>("get", baseUrlApi("/admin/system/Menu/all"), {
    params
  });
};

/** 获取系统管理-菜单增加 */
export const addMenu = (data?: object) => {
  return http.request<Result>("post", baseUrlApi("/admin/system/Menu/add"), {
    data
  });
};
/** 获取系统管理-菜单修改 */
export const updateMenu = (data?: object) => {
  return http.request<Result>("put", baseUrlApi("/admin/system/Menu/update"), {
    data
  });
};

/** 获取系统管理-菜单删除 */
export const deleteMenu = (params?: object) => {
  return http.request<Result>(
    "delete",
    baseUrlApi("/admin/system/Menu/delete"),
    {
      params
    }
  );
};

/** 获取系统管理-部门管理列表 */
export const getDeptList = (data?: object) => {
  return http.request<Result>("post", baseUrlApi("/admin/system/dept/all"), {
    data
  });
};

/** 修改系统管理-部门信息 */
export const updateDept = (data?: object) => {
  return http.request<Result>("put", baseUrlApi("/admin/system/dept/update"), {
    data
  });
};

/** 删除系统管理-部门信息 */
export const deleteDept = (params?: object) => {
  return http.request<Result>(
    "delete",
    baseUrlApi("/admin/system/dept/delete"),
    {
      params
    }
  );
};

/** 添加系统管理-部门信息 */
export const addDept = (data?: object) => {
  return http.request<Result>("post", baseUrlApi("/admin/system/dept/add"), {
    data
  });
};

/** 获取系统监控-在线用户列表 */
export const getOnlineLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/online-logs", { data });
};

/** 获取系统监控-登录日志列表 */
export const getLoginLogsList = (data?: object) => {
  return http.request<ResultTable>(
    "post",
    baseUrlApi("/admin/monitor/login/logs"),
    {
      data
    }
  );
};
/** 获取系统监控-登录日志-批量删除 */
export const batchDeleteLoginLogs = (data?: Array<number>) => {
  return http.request<Result>(
    "delete",
    baseUrlApi("/admin/monitor/login/batch_delete"),
    {
      data
    }
  );
};
/** 清空登录日志 */
export const clearLoginLogs = () => {
  return http.request<Result>(
    "delete",
    baseUrlApi("/admin/monitor/login/clear")
  );
};

/** 获取系统监控-操作日志列表 */
export const getOperationLogsList = (data?: object) => {
  return http.request<ResultTable>(
    "post",
    baseUrlApi("/admin/monitor/operation/logs"),
    {
      data
    }
  );
};

/** 查看当前管理员操作日志记录 */
export const getCurrentOperationLogs = (data?: object) => {
  return http.request<ResultTable>(
    "post",
    baseUrlApi("/admin/monitor/operation/current"),
    {
      data
    }
  );
};

/** 获取系统监控-操作日志-批量删除 */
export const batchDeleteOperationLogs = (data?: Array<number>) => {
  return http.request<Result>(
    "delete",
    baseUrlApi("/admin/monitor/operation/batch_delete"),
    {
      data
    }
  );
};

/** 清空操作日志 */
export const clearOperationLogs = () => {
  return http.request<Result>(
    "delete",
    baseUrlApi("/admin/monitor/operation/clear")
  );
};

/** 获取系统监控-系统日志列表 */
export const getSystemLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/system-logs", { data });
};

/** 获取系统监控-系统日志-根据 id 查日志详情 */
export const getSystemLogsDetail = (data?: object) => {
  return http.request<Result>("post", "/system-logs-detail", { data });
};

/** 获取角色管理-权限-菜单权限 */
export const getRoleMenu = (data?: object) => {
  return http.request<Result>(
    "get",
    baseUrlApi("/admin/system/role/role_menu"),
    { data }
  );
};

/** 获取角色管理-权限-菜单权限-根据角色 id 查对应菜单 */
export const getRoleMenuIds = (params?: object) => {
  return http.request<Result>("get", baseUrlApi("/admin/system/role/menu"), {
    params
  });
};

/** 获取角色管理-权限-菜单权限-修改 */
export const updateRoleMenu = (data?: object) => {
  return http.request<Result>("post", baseUrlApi("/admin/system/role/assign"), {
    data
  });
};

/** 获取角色管理-单独修改角色状态 */
export const updateRoleStatus = (params?: object) => {
  return http.request<Result>("put", baseUrlApi("/admin/system/role/status"), {
    params
  });
};

/** 获取定时任务 */
export const getTaskList = (data?: object) => {
  return http.request<ResultTable>(
    "post",
    baseUrlApi("/admin/monitor/task/tasks"),
    {
      data
    }
  );
};

/** 获取定时任务-新增 */
export const addTask = (data?: object) => {
  return http.request<Result>("post", baseUrlApi("/admin/monitor/task/add"), {
    data
  });
};

/** 获取定时任务-删除 */
export const deleteTask = (params?: object) => {
  return http.request<Result>(
    "delete",
    baseUrlApi("/admin/monitor/task/delete"),
    {
      params
    }
  );
};

/** 获取定时任务-执行 */
export const runTask = (params?: object) => {
  return http.request<Result>("post", baseUrlApi("/admin/monitor/task/run"), {
    params
  });
};

/** 获取定时任务-暂停 */
export const pauseTask = (params?: object) => {
  return http.request<Result>("post", baseUrlApi("/admin/monitor/task/pause"), {
    params
  });
};

/** 获取定时任务-恢复 */
export const resumeTask = (params?: object) => {
  return http.request<Result>(
    "post",
    baseUrlApi("/admin/monitor/task/resume"),
    {
      params
    }
  );
};

/** 获取定时任务-日志 */
export const getTaskLogs = (data?: object) => {
  return http.request<ResultTable>(
    "post",
    baseUrlApi("/admin/monitor/task/record"),
    {
      data
    }
  );
};
